
//using MoreMountains.NiceVibrations;
using UnityEngine;

public class ActionStatePlayerIdle : ActionStateIdle
{
    public ActionStatePlayerIdle(PlayerActionFSM fsm) : base(fsm)
    {
        
    }

    public override void OnEnter(FSMState preState)
    {
        base.OnEnter(preState);
        
        
    }
}

/// <summary>
/// 移动
/// </summary>
public class ActionStateRun : ActionState
{
    public override int stateId => ActionStateType.run;

    public ActionStateRun(PlayerActionFSM fsm) : base(fsm)
    {
        
    }

    public override void OnEnter(FSMState preState)
    {
        base.OnEnter(preState);
        
        //GameDebug.LogError($"player move");
        Player player = this.role as Player;
        if (player)
        {
            player.AdjustDir(player.transform.forward);
            
            //player.roleAnim.animator.SetFloat("RunAnim",player.runAnim);
            if (role.roleAnim)
                role.roleAnim.SetAnimatorBool("Move", true);
        }
    }

    private float moveAnimSpeedFactor = 15;
    
    public override void Update(float deltaTime)
    {
        base.Update(deltaTime);

        if (Time.frameCount % 50 == 0)
        {
            if (role.roleAnim)
                role.roleAnim.SetAnimatorBool("Move", true);
        }
    }
}
/// <summary>
/// idle -> run
/// </summary>
public class Idle2RunTransition : ActionTransition
{
    public Idle2RunTransition(ActionState @from, ActionState to) : base(@from, to)
    {

    }

    public override bool Meet()
    {
        //return role.realMoveVec.sqrMagnitude > 0;
        Player player = this.role as Player;
        if (player)
            return player.ctrlMoveVec.sqrMagnitude > 0;

        return false;
    }
}
/// <summary>
/// run -> idle
/// </summary>
public class Run2IdleTransition : ActionTransition
{
    public Run2IdleTransition(ActionState @from, ActionState to) : base(@from, to)
    {

    }

    public override bool Meet()
    {
        Player player = this.role as Player;
        if (player)
            return player.ctrlMoveVec.sqrMagnitude <= 0;

        return false;
    }
}

public class ActionStatePlayerAttack : ProgressAction
{
    public override int stateId => ActionStateType.attack;
    
    public ActionStatePlayerAttack(PlayerActionFSM fsm) : base(fsm)
    {
        m_TotalTime = 1f;
        m_ExecuteTime = 0.2f;
    }

    public override void OnEnter(FSMState preState)
    {
        base.OnEnter(preState);

        Player player = this.role as Player;
        player.roleAnim.SetAnimatorBool("Attack",true);

        GameDebug.LogShowy($"Player attack:{Time.time}");

    }

    protected override void OnExecute()
    {
        base.OnExecute();
        
    }


    public override void OnExit(FSMState nextState)
    {
        base.OnExit(nextState);

    }
}


public class ActionStateWin : ActionState
{
    public override int stateId => MActionStateType.win;

    public ActionStateWin(PlayerActionFSM fsm) : base(fsm)
    {

    }

    public override void OnEnter(FSMState preState)
    {
        base.OnEnter(preState);

        Player player = this.role as Player;

        player.StopMove();

        if(player.roleAnim)
            player.roleAnim.SetAnimatorTrigger("Win");

        player.mBattleController.win = true;
        
        GameDebug.LogError($"{role.name} Win");
    }

    public override void OnExit(FSMState nextState)
    {
        base.OnExit(nextState);

        Player player = this.role as Player;
        
    }
}


public class ActionStatePlayerDie : ActionStateDie
{
    public ActionStatePlayerDie(PlayerActionFSM fsm) : base(fsm)
    {
        
    }

    public override void OnEnter(FSMState preState)
    {
        base.OnEnter(preState);

        Player player = this.role as Player;
        player.mBattleController.fail = true;
        
    }
}

